home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / stdio / io.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-05  |  4.4 KB  |  164 lines

  1. /* @(#)io.h    2.9 98/09/05 Copyright 1986, 1995 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1986, 1995 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <standard.h>
  23. #include <unixstd.h>
  24. #include <fctldefs.h>
  25.  
  26. #ifdef    NO_USG_STDIO
  27. #    ifdef    HAVE_USG_STDIO
  28. #        undef    HAVE_USG_STDIO
  29. #    endif
  30. #endif
  31.  
  32. /*
  33.  * speed things up...
  34.  */
  35. #define    _openfd(name, omode)    (open(name, omode, 0666))
  36.  
  37. #define    DO_MYFLAG        /* use local flags */
  38.  
  39. /*
  40.  * Flags used during fileopen(), ... by _fcons()/ _cvmod()
  41.  */
  42. #define    FI_NONE        0x0000    /* no flags defined */
  43.  
  44. #define    FI_READ        0x0001    /* open for reading */
  45. #define    FI_WRITE    0x0002    /* open for writing */
  46. #define    FI_BINARY    0x0004    /* open in binary mode */
  47.  
  48. #define    FI_CREATE    0x0010    /* create if nessecary */
  49. #define    FI_TRUNC    0x0020    /* truncate file on open */
  50. #define    FI_APPEND    0x0040    /* append on each write */
  51. #define    FI_UNBUF    0x0080    /* dont't buffer io */
  52. #define    FI_CLOSE    0x1000    /* close file on error */
  53.  
  54. /*
  55.  * local flags
  56.  */
  57. #define    _IONORAISE    01    /* do no raisecond() on errors */
  58. #define    _IOUNBUF    02    /* do unbuffered i/o */
  59.  
  60. #ifdef    DO_MYFLAG
  61.  
  62. struct _io_flags {
  63.     FILE    *fl_io;        /* file pointer */
  64.     struct _io_flags    /* pointer to next struct */
  65.         *fl_next;    /* if more file pointer to same fd */
  66.     int    fl_flags;    /* my flags */
  67. };
  68.  
  69. typedef    struct _io_flags _io_fl;
  70.  
  71. extern    int    _io_glflag;    /* global default flag */
  72. extern    _io_fl    *_io_myfl;    /* array of structs to hold my flags */
  73. extern    int    _fl_max;    /* max fd currently in _io_myfl */
  74.  
  75. /*
  76.  *    if fileno > max
  77.  *        expand
  78.  *    else if map[fileno].pointer == 0
  79.  *        return 0
  80.  *    else if map[fileno].pointer == p
  81.  *        return map[fileno].flags
  82.  *    else
  83.  *        search list
  84.  */
  85. #define    flp(p)        (&_io_myfl[fileno(p)])
  86.  
  87. #ifdef    MY_FLAG_IS_MACRO
  88. #define    my_flag(p)    ((int)fileno(p) >= _fl_max ?            \
  89.                 _io_get_my_flag(p) :            \
  90.             ((flp(p)->fl_io == 0 || flp(p)->fl_io == p) ?    \
  91.                 flp(p)->fl_flags :            \
  92.                 _io_get_my_flag(p)))
  93. #else
  94. #define    my_flag(p)    _io_get_my_flag(p)
  95. #endif
  96.  
  97. #define    set_my_flag(p,v) _io_set_my_flag(p, v)
  98. #define    add_my_flag(p,v) _io_add_my_flag(p, v)
  99.  
  100. extern    int    _io_get_my_flag __PR((FILE *));
  101. extern    void    _io_set_my_flag __PR((FILE *, int));
  102. extern    void    _io_add_my_flag __PR((FILE *, int));
  103.  
  104. #else    /* DO_MYFLAG */
  105.  
  106. #define    my_flag(p)        _IONORAISE    /* Always noraise */
  107. #define    set_my_flag(p,v)            /* Ignore */
  108. #define    add_my_flag(p,v)            /* Ignore */
  109.  
  110. #endif    /* DO_MYFLAG */
  111.  
  112. #ifdef    HAVE_USG_STDIO
  113. /*
  114.  * Define prototypes to verify if our interface is right
  115.  */
  116. extern    int    _filbuf    __PR((FILE *));
  117. extern    int    _flsbuf    __PR((int, FILE *));
  118. #else
  119. /*
  120.  * If we are on a non USG system we cannot down file pointers
  121.  */
  122. #undef    DO_DOWN
  123. #endif
  124.  
  125. #ifndef    DO_DOWN
  126. /*
  127.  *    No stream checking
  128.  */
  129. #define    down(f)
  130. #define    down1(f,fl1)
  131. #define    down2(f,fl1,fl2)
  132. #else
  133. /*
  134.  *    Do stream checking (works only on USG stdio)
  135.  *
  136.  *    New version of USG stdio.
  137.  *    _iob[] holds only a small amount of pointers.
  138.  *    Aditional space is allocated.
  139.  *    We may check only if the file pointer is != NULL
  140.  *    and if iop->_flag refers to a stream with appropriate modes.
  141.  *    If _iob[] gets expanded by malloc() we cannot check upper bound.
  142.  */
  143. #define down(f)        ((f) == 0 || (f)->_flag==0 ? \
  144.                 (raisecond(_badfile, 0L),(FILE *)0) : (f))
  145.  
  146. #define down1(f,fl1)    ((f) == 0 || (f)->_flag==0 ? \
  147.                     (raisecond(_badfile, 0L),(FILE *)0) : \
  148.                 (((f)->_flag & fl1) != fl1 ? \
  149.                     (raisecond(_badop, 0L),FILE *)0) : \
  150.                     (f)))
  151.  
  152. #define down2(f,fl1,fl2)((f) == 0 || (f)->_flag==0 ? \
  153.                 (raisecond(_badfile, 0L),(FILE *)0) : \
  154.             (((f)->_flag & fl1) != fl1 && \
  155.              ((f)->_flag & fl2) != fl2 ? \
  156.                 (raisecond(_badop, 0L),(FILE *)0) : \
  157.                 (f)))
  158. #endif    /* DO_DOWN */
  159.  
  160. extern    char    _badfile[];
  161. extern    char    _badmode[];
  162. extern    char    _badop[];
  163.  
  164.